<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Function template condition_if_c</title>
<link rel="stylesheet" href="../../../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="Chapter 1. Boost.Contract 1.0.0">
<link rel="up" href="../../reference.html#header.boost.contract.call_if_hpp" title="Header &lt;boost/contract/call_if.hpp&gt;">
<link rel="prev" href="call_if.html" title="Function template call_if">
<link rel="next" href="condition_if.html" title="Function template condition_if">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../boost.png"></td>
<td align="center"><a href="../../../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="call_if.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../reference.html#header.boost.contract.call_if_hpp"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="condition_if.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.contract.condition_if_c"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Function template condition_if_c</span></h2>
<p>boost::contract::condition_if_c — Select compilation and execution of a boolean functor template condition using a static boolean predicate (not needed on C++17 compilers, use <code class="computeroutput">if constexpr</code> instead). </p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../reference.html#header.boost.contract.call_if_hpp" title="Header &lt;boost/contract/call_if.hpp&gt;">boost/contract/call_if.hpp</a>&gt;

</span>
<span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">bool</span> Pred<span class="special">,</span> <span class="keyword">typename</span> Then<span class="special">&gt;</span> 
  <span class="keyword">bool</span> <span class="identifier">condition_if_c</span><span class="special">(</span><span class="identifier">Then</span> f<span class="special">,</span> <span class="keyword">bool</span> else_ <span class="special">=</span> <span class="keyword">true</span><span class="special">)</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="idm45885987470416"></a><h2>Description</h2>
<p>Compile and execute the nullary boolean functor template call <code class="computeroutput">f()</code> if and only if the specified static boolean predicate <code class="computeroutput">Pred</code> is <code class="computeroutput">true</code>, otherwise trivially return <code class="computeroutput">else_</code> (<code class="computeroutput">true</code> by default) at run-time.</p>
<p>A call to <code class="computeroutput">boost::contract::condition_if_c&lt;Pred&gt;(f, else_)</code> is logically equivalent to <code class="computeroutput">boost::contract::call_if_c&lt;Pred&gt;(f, [] { return else_; })</code> (but its internal implementation is optimized and it does not actually use <code class="computeroutput">call_if_c</code>).</p>
<p><span class="bold"><strong>See Also:</strong></span></p>
<p> <a class="link" href="../../boost_contract/extras.html#boost_contract.extras.assertion_requirements__templates_" title="Assertion Requirements (Templates)">
        Assertion Requirements</a></p>
<p>
</p>
<p>




</p>
<div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term">Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody>
<tr>
<td><p><span class="term"><code class="computeroutput">else_</code></span></p></td>
<td><p>Boolean value to return when <code class="computeroutput">Pred</code> is <code class="computeroutput">false</code> (instead of compiling and executing the functor template call <code class="computeroutput">f()</code>).</p></td>
</tr>
<tr>
<td><p><span class="term"><code class="computeroutput">f</code></span></p></td>
<td><p>Nullary boolean functor template. The functor template call <code class="computeroutput">f()</code> is compiled and executed if and only if <code class="computeroutput">Pred</code> is <code class="computeroutput">true</code>.</p></td>
</tr>
</tbody>
</table></div></td>
</tr>
<tr>
<td><p><span class="term">Template Parameters:</span></p></td>
<td><div class="variablelist"><table border="0" class="variablelist compact">
<colgroup>
<col align="left" valign="top">
<col>
</colgroup>
<tbody><tr>
<td><p><span class="term"><code class="computeroutput">Pred</code></span></p></td>
<td><p>Static boolean predicate selecting when the functor template call <code class="computeroutput">f()</code> should be compiled and executed. </p></td>
</tr></tbody>
</table></div></td>
</tr>
<tr>
<td><p><span class="term">Returns:</span></p></td>
<td><p>Boolean value returned by <code class="computeroutput">f()</code> if the static predicate <code class="computeroutput">Pred</code> is <code class="computeroutput">true</code>. Otherwise, trivially return <code class="computeroutput">else_</code>. </p></td>
</tr>
</tbody>
</table></div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2008-2019 Lorenzo Caminiti<p>
        Distributed under the Boost Software License, Version 1.0 (see accompanying
        file LICENSE_1_0.txt or a copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="call_if.html"><img src="../../../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../reference.html#header.boost.contract.call_if_hpp"><img src="../../../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="condition_if.html"><img src="../../../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
